//
//  MissPwdViewController.m
//  HYNetApp
//
//  Created by 秦乾龙 on 16/10/19.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "MissPwdViewController.h"
#import "AFNetworking.h"//主要用于网络请求方法
#import "UIKit+AFNetworking.h"//里面有异步加载图片的方法
#import "AFHTTPSessionManager.h"
#import "NavView.h"
#import "ZYTextField.h"
#import "IndexNewViewController.h"
#import "ChooseSignViewController.h"

@interface MissPwdViewController ()<UITextFieldDelegate>
@property (nonatomic,retain)NSString *phoneNumer;
@property (nonatomic,retain)NSDictionary *allDic;
@property (nonatomic,retain) ZYTextField *psdfield;
@property (nonatomic,retain) UIButton *getCodeBtn;
@property (nonatomic,retain) UIView *phoneNumerView;
@property (nonatomic,retain) UIButton *registBtn;
@property (nonatomic,retain) UIView *codeView;
@property (nonatomic,retain) ZYTextField *msgCodeTextField;
@property (nonatomic,retain) ZYTextField *phoneNumerTextField;

@property (nonatomic,retain) UIView *psdView;
@property (nonatomic,retain) UIView *loginView;

@end

@implementation MissPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setUI];
}
- (void)setUI
{
    NavView *nav = [[NavView alloc]initWithTitle:@"重设密码" LeftImage:[ UIImage imageNamed:@"返回"]];
    nav.frame = CGRectMake(0, 20, ScreenW, 44);
//    nav.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    nav.titleLable.textColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    [nav.leftBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    nav.backView.alpha = 0.1f;
    [self.view addSubview:nav];
    
    
    CGFloat spaceToTop = 64;
    CGFloat spaceToNav = 80*kScale;
    
    CGFloat leftSpace = 48*kScale;
    CGFloat publicFieldH =  158*kScale;
    CGFloat publicH =  48*kScale;
    UIImageView *phoneImage = [[UIImageView alloc]init];
    phoneImage.image = [UIImage imageNamed:@"手机"];
    phoneImage.frame = CGRectMake(leftSpace, spaceToTop+spaceToNav, publicH, publicH);
    [self.view addSubview:phoneImage];
    
    _phoneNumerTextField = [[ZYTextField alloc]init];
    _phoneNumerTextField.frame = CGRectMake(leftSpace*2+56*kScale, spaceToTop+spaceToNav, ScreenW, publicH);
    _phoneNumerTextField.textColor = [UIColor whiteColor];
    _phoneNumerTextField.placeholder = @"请输入手机号码";
    _phoneNumerTextField.delegate =self;
    _phoneNumerTextField.tag = 10;
    _phoneNumerTextField.keyboardType = UIKeyboardTypePhonePad;
//    _phoneNumerTextField.secureTextEntry = YES;
    [self.view addSubview:_phoneNumerTextField];
    UIView *lineView = [[UIView alloc]init];
    lineView.frame = CGRectMake(leftSpace, spaceToTop+publicFieldH, ScreenW-2*leftSpace, 1*kScale);
    lineView.backgroundColor = ZallColorFromRGB(0x3a3a3a);
    [self.view addSubview:lineView];
    //验证码
    UIImageView *codeImage = [[UIImageView alloc]init];
    codeImage.image = [UIImage imageNamed:@"验证码"];
    codeImage.frame = CGRectMake(leftSpace, spaceToTop+spaceToNav+publicFieldH, publicH, publicH);
    [self.view addSubview:codeImage];
    
    _msgCodeTextField = [[ZYTextField alloc]init];
    //暂时的frame
    _msgCodeTextField.frame = CGRectMake(leftSpace*2+56*kScale, spaceToTop+spaceToNav+publicFieldH, ScreenW, publicH);
    _msgCodeTextField.textColor = [UIColor whiteColor];
    _msgCodeTextField.placeholder = @"请输入验证码";
    _msgCodeTextField.delegate =self;
    _msgCodeTextField.tag = 12;
    _msgCodeTextField.keyboardType = UIKeyboardTypePhonePad;
    [self.view addSubview:_msgCodeTextField];
    
    _getCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
//    [_getCodeBtn setTitleColor:ZallColorFromRGB(0x1fa2b6) forState:UIControlStateNormal];
    [_getCodeBtn setTitleColor:[UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f] forState:UIControlStateNormal];
    [_getCodeBtn setTitle:@"重新发送(59)" forState:UIControlStateNormal];
    _getCodeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    CGSize codeBtnSize = [_getCodeBtn sizeThatFits:CGSizeMake(MAXFLOAT, publicH)];
    _getCodeBtn.frame = CGRectMake(ScreenW-leftSpace-codeBtnSize.width, spaceToTop+spaceToNav+publicFieldH, codeBtnSize.width, publicH);
    [_getCodeBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
    [_getCodeBtn addTarget:self action:@selector(getCodeClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_getCodeBtn];
    //重置frame
    _msgCodeTextField.frame = CGRectMake(leftSpace*2+56*kScale, spaceToTop+spaceToNav+publicFieldH, ScreenW-leftSpace*5-56*kScale-codeBtnSize.width+15*kScale, publicH);
//    _msgCodeTextField.frame = CGRectMake(leftSpace*2+56*kScale, spaceToTop+spaceToNav+publicFieldH, ScreenW, publicH);
    UIView *lineView2 = [[UIView alloc]init];
    lineView2.frame = CGRectMake(ScreenW-codeBtnSize.width-2*leftSpace+15*kScale, spaceToTop+spaceToNav+publicFieldH+10*kScale, 3*kScale, 28*kScale);
    lineView2.backgroundColor = ZallColorFromRGB(0x8e8e8e);
    [self.view addSubview:lineView2];
    UIView *lineView3 = [[UIView alloc]init];
    lineView3.frame = CGRectMake(leftSpace, spaceToTop+publicFieldH*2, ScreenW-2*leftSpace, 2*kScale);
    lineView3.backgroundColor = ZallColorFromRGB(0x3a3a3a);
    [self.view addSubview:lineView3];
    //重置frame
//    _msgCodeTextField.frame = CGRectMake(leftSpace*2+56*kScale, spaceToTop+spaceToNav+publicFieldH*3, ScreenW-leftSpace*5-56*kScale-codeBtnSize.width, publicH);
    UIImageView *lockImage = [[UIImageView alloc]init];
    lockImage.image = [UIImage imageNamed:@"锁"];
    lockImage.frame = CGRectMake(leftSpace, spaceToTop+spaceToNav+publicFieldH*2, publicH, publicH);
    [self.view addSubview:lockImage];
    
    _psdfield = [[ZYTextField alloc]init];
    _psdfield.frame = CGRectMake(leftSpace*2+56*kScale, spaceToTop+spaceToNav+publicFieldH*2, ScreenW-leftSpace*4-56*kScale-publicH, publicH);
    _psdfield.textColor = [UIColor whiteColor];
    
    _psdfield.placeholder = @"请输入密码(至少6位数)";
    _psdfield.delegate =self;
    _psdfield.tag = 11;
    _psdfield.secureTextEntry = YES;
    _psdfield.keyboardType = UIKeyboardTypeASCIICapable;
    [self.view addSubview:_psdfield];
    UIButton *eyeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    eyeBtn.frame = CGRectMake(ScreenW-publicH*2, spaceToTop+spaceToNav+publicFieldH*2, publicH, publicH);
    [eyeBtn setImage:[UIImage imageNamed:@"闭眼"] forState:UIControlStateNormal];
    [eyeBtn setImage:[UIImage imageNamed:@"睁眼"] forState:UIControlStateSelected];
    [eyeBtn addTarget:self action:@selector(eyeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:eyeBtn];
    UIView *lineView4 = [[UIView alloc]init];
    lineView4.frame = CGRectMake(leftSpace, spaceToTop+publicFieldH*3, ScreenW-2*leftSpace, 1*kScale);
    lineView4.backgroundColor = ZallColorFromRGB(0x3a3a3a);
    [self.view addSubview:lineView4];
    
    
    
    CGFloat commitBtnToPwd = 96*kScale;
    CGFloat commitBtnH = 120*kScale;
    UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    commitBtn.frame = CGRectMake(leftSpace, spaceToTop+publicFieldH*3+commitBtnToPwd, ScreenW-2*leftSpace, commitBtnH);
    commitBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    commitBtn.backgroundColor = ZallColorFromRGB(0x1fa2b6);
    commitBtn.layer.cornerRadius = commitBtnH/2.0;
    [commitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [commitBtn addTarget:self action:@selector(changeClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitBtn];
    
    }

-(BOOL)textField:(ZYTextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"%@",NSStringFromRange(range));
    if (textField.tag==10)
    {
        if (textField) {
            NSString* text = textField.text;
            //删除
            if([string isEqualToString:@""]){
                
                //删除一位
                if(range.length == 1){
                    //最后一位,遇到空格则多删除一次
                    if (range.location == text.length-1 ) {
                        if ([text characterAtIndex:text.length-1] == ' ') {
                            [textField deleteBackward];
                        }
                        return YES;
                    }
                    //从中间删除
                    else{
                        NSInteger offset = range.location;
                        
                        if (range.location < text.length && [text characterAtIndex:range.location] == ' ' && [textField.selectedTextRange isEmpty]) {
                            [textField deleteBackward];
                            offset --;
                        }
                        [textField deleteBackward];
                        textField.text = [self parseString:textField.text];
                        UITextPosition *newPos = [textField positionFromPosition:textField.beginningOfDocument offset:offset];
                        textField.selectedTextRange = [textField textRangeFromPosition:newPos toPosition:newPos];
                        return NO;
                    }
                }
                else if (range.length > 1) {
                    BOOL isLast = NO;
                    //如果是从最后一位开始
                    if(range.location + range.length == textField.text.length ){
                        isLast = YES;
                    }
                    [textField deleteBackward];
                    textField.text = [self parseString:textField.text];
                    
                    NSInteger offset = range.location;
                    if (range.location == 3 || range.location  == 8) {
                        offset ++;
                    }
                    if (isLast) {
                        //光标直接在最后一位了
                    }else{
                        UITextPosition *newPos = [textField positionFromPosition:textField.beginningOfDocument offset:offset];
                        textField.selectedTextRange = [textField textRangeFromPosition:newPos toPosition:newPos];
                    }
                    
                    return NO;
                }
                
                else{
                    return YES;
                }
            }
            
            else if(string.length >0){
                
                //限制输入字符个数
                if (([self noneSpaseString:textField.text].length + string.length - range.length > 11) ) {
                    return NO;
                }
                //判断是否是纯数字(千杀的搜狗，百度输入法，数字键盘居然可以输入其他字符)
                //            if(![string isNum]){
                //                return NO;
                //            }
                [textField insertText:string];
                textField.text = [self parseString:textField.text];
                
                NSInteger offset = range.location + string.length;
                if (range.location == 3 || range.location  == 8) {
                    offset ++;
                }
                UITextPosition *newPos = [textField positionFromPosition:textField.beginningOfDocument offset:offset];
                textField.selectedTextRange = [textField textRangeFromPosition:newPos toPosition:newPos];
                return NO;
            }else{
                return YES;
            }
            
        }
    }
    
    
    return YES;
    
}

-(NSString*)noneSpaseString:(NSString*)string
{
    return [string stringByReplacingOccurrencesOfString:@" " withString:@""];
}

- (NSString*)parseString:(NSString*)string
{
    if (!string) {
        return nil;
    }
    NSMutableString* mStr = [NSMutableString stringWithString:[string stringByReplacingOccurrencesOfString:@" " withString:@""]];
    if (mStr.length >3) {
        [mStr insertString:@" " atIndex:3];
    }if (mStr.length > 8) {
        [mStr insertString:@" " atIndex:8];
        
    }
    
    return  mStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//密码显示
- (void)eyeBtnClick:(UIButton*)sender
{
    if (sender.selected==YES) {
        sender.selected = NO;
        _psdfield.secureTextEntry = YES;
    }
    else
    {
        sender.selected = YES;
        _psdfield.secureTextEntry = NO;
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)backClick:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)getCodeClick:(id)sender
{
    _phoneNumer = [_phoneNumerTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
//    //验证是否是手机号
//    NSString *regex =@"^((1[3-8][0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
//    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//    BOOL isMatch = [pred evaluateWithObject:_phoneNumer];
//    if (isMatch==YES) {
        NSString *urlStr = [NSString stringWithFormat:@"%@/sys/login/memberRegistr/sms/randomCode?mobile_no=%@",APIYIGOU,_phoneNumer];

        DYBaseRequest *request = [DYBaseRequest new];
        request.requestUrl = urlStr;
        [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
            NSLog(@"77777%@",allDic);
            
            //                    [defaults setObject:dataDic forKey:@"request"];
            //                NSDictionary *dataDic = allDic[@"data"];
            //测试
            //_msgCodeTextField.text = allDic[@"data"];
            [self timeRun];
            
        } error:^(YTKBaseRequest *request) {
           [ViewFactory showInfoMsg:@"获取验证码失败"];
            
        } failure:^(YTKBaseRequest *request) {
            [ViewFactory showErrorStrMsg:NETWORK_ERR];
        }];
//    }
//    else
//    {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"请输入有效手机号码" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil];
//        [alert show];
//    }
}
//倒计时
- (void)timeRun
{
    __block NSInteger time = 29; //倒计时时间
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    
    dispatch_source_set_event_handler(_timer, ^{
        
        if(time <= 0){ //倒计时结束，关闭
            
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置按钮的样式
                [_getCodeBtn setTitle:@"重新发送" forState:UIControlStateNormal];
//                [_getCodeBtn setTitleColor:[UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f] forState:UIControlStateNormal];
                [_getCodeBtn setTitleColor:[UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f] forState:UIControlStateNormal];
                _getCodeBtn.userInteractionEnabled = YES;
            });
            
        }else{
            
            int seconds = time % 60;
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置按钮显示读秒效果
                [_getCodeBtn setTitle:[NSString stringWithFormat:@"重新发送(%.2d)", seconds] forState:UIControlStateNormal];
                [_getCodeBtn setTitleColor:[UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f] forState:UIControlStateNormal];
                _getCodeBtn.userInteractionEnabled = NO;
            });
            time--;
        }
    });
    dispatch_resume(_timer);
}

- (BOOL) textFieldShouldBeginEditing:(ZYTextField *)textField
{
//    if (textField.tag == 11) {
//        _phoneNumerView.backgroundColor = [UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
////        _phoneNumerTextField.textColor =[UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//        if ([_msgCodeTextField.text isEqualToString:@""]&&![_psdTextField.text isEqualToString:@""]) {
//            _loginView.backgroundColor = [UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//            //        [_loginView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        }
//        else
//        {
//            _loginView.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
//        }
//
//        
//    }
//    if (textField.tag == 12) {
//        _codeView.backgroundColor = [UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
////        _msgCodeTextField.textColor =[UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//        if (![_phoneNumerTextField.text isEqualToString:@""]&&![_psdTextField.text isEqualToString:@""]) {
//            _loginView.backgroundColor = [UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//            //        [_loginView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        }
//        else
//        {
//            _loginView.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
//        }
//
//    }
//    if (textField.tag == 13) {
//        _psdView.backgroundColor = [UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//        _psdTextField.textColor =[UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//        if (![_phoneNumerTextField.text isEqualToString:@""]&&![_msgCodeTextField.text isEqualToString:@""])
//        {
//            _loginView.backgroundColor = [UIColor colorWithRed:171/255.0 green:147/255.0 blue:103/255.0 alpha:1.0f];
//            //        [_loginView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        }
//        else
//        {
//            _loginView.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
//        }
//
//    }
    
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(ZYTextField *)textField
{
    
    if (textField.tag == 11) {
        _phoneNumerView.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
        //        _phoneNumerTextField.textColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
        
    }
    if (textField.tag == 12) {
        _codeView.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
        //        _msgCodeTextField.textColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
        
    }
    if (textField.tag == 13) {
        _psdView.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
        //        _psdTextField.textColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1.0f];
        
    }
    return YES;
}


- (IBAction)changeClick:(id)sender
{
    
    NSString *random = _msgCodeTextField.text;
    NSString *pwd = _psdfield.text;
    if (pwd.length>=6&&random.length!=0)
    {
//        sys/login/password/rest?mobile_no=18771054407&user_newPwd=qql123&reg_num=9432
        NSString *urlStr = [NSString stringWithFormat:@"%@/sys/login/password/rest?mobile_no=%@&user_newPwd=%@&reg_num=%@",APIYIGOU,[_phoneNumerTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""],pwd,random];

        DYBaseRequest *request = [DYBaseRequest new];
        request.requestUrl = urlStr;
        [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
            NSLog(@"77777%@",allDic);
            
            NSString *urlStr = [NSString stringWithFormat:@"%@/sys/login/memberLogin?mobile_no=%@&user_pwd=%@",APIYIGOU,[_phoneNumerTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""],_psdfield.text];
            DYLog(@"1111111%@",urlStr);
            DYBaseRequest *request2 = [DYBaseRequest new];
            request2.requestUrl = urlStr;
            [request2 dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
                NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
                NSLog(@"77777%@",allDic);
                
                [UserData login:[allDic objectForKey:@"data"]];
                                //                        ZYtabBarViewController *hyTabbarVC = [[ZYtabBarViewController alloc]init];
                //                        [self.navigationController pushViewController:hyTabbarVC animated:YES];
                NSString *isJionTribe = [NSString stringWithFormat:@"%@",allDic[@"data"][@"isJoinTribe"]] ;
                if ([isJionTribe isEqualToString:@"0"]) {
                    ChooseSignViewController *choseSign = [[ChooseSignViewController alloc]init];
                    [self.navigationController pushViewController:choseSign animated:YES];
                }
                else
                {
                    self.navigationController.navigationBarHidden = NO;
                    for (UIViewController *temp in self.navigationController.viewControllers) {
                        if ([temp isKindOfClass:[IndexNewViewController class]]) {
                            [[NSNotificationCenter defaultCenter] postNotificationName:POST_LOGINSUC object:nil];
                            [self.navigationController popToViewController:temp animated:YES];
                        }
                    } ;
                }

                self.navigationController.navigationBarHidden = NO;
            } error:^(YTKBaseRequest *request) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登录失败" message:@"用户名与密码不符" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];
                [alert show];
                
            } failure:^(YTKBaseRequest *request) {
                [ViewFactory showErrorStrMsg:NETWORK_ERR];
            }];
        } error:^(YTKBaseRequest *request) {
            NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
            NSLog(@"77777%@",allDic);
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:allDic[@"message"] delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil];
            [alert show];
            
        } failure:^(YTKBaseRequest *request) {
            [ViewFactory showErrorStrMsg:NETWORK_ERR];
        }];
    }
    else if (random.length==0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"请输入完整信息" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil];
        [alert show];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"请输入6位以上字母和数字密码" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil];
        [alert show];
    }

}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_phoneNumerTextField resignFirstResponder];
    [_psdfield resignFirstResponder];
    [_msgCodeTextField resignFirstResponder];
    
}
@end
